/**
 * @author qihui
 * 2009-10-6
 */
package com.qihui.ssh.dao.sys;

import java.io.Serializable;
import java.util.List;
import org.springframework.orm.hibernate3.support.HibernateDaoSupport;

import com.qihui.ssh.dao.entities.BasePOJO;

@SuppressWarnings("rawtypes")
public class BaseDAOImpl extends HibernateDaoSupport implements BaseDAO {

	/**
	 * Create POJO
	 * 
	 * @param basePOJO
	 * @return BasePOJO The return of a lasting state of POJO
	 */
	public BasePOJO createPOJO(BasePOJO basePOJO) {
		this.getHibernateTemplate().save(basePOJO);
		return basePOJO;
	}

	/**
	 * Update POJO
	 * 
	 * @param basePOJO
	 */
	public void updatePOJO(BasePOJO basePOJO) {
		this.getHibernateTemplate().update(basePOJO);
	}

	/**
	 * Merge POJO
	 * 
	 * @param basePOJO
	 */
	public void mergePOJO(BasePOJO basePOJO) {
		this.getHibernateTemplate().merge(basePOJO);
	}

	/**
	 * Delete POJO
	 * 
	 * @param c
	 * @param id
	 */

	public void deletePOJO(Class c, Serializable id) {
		this.getHibernateTemplate().delete(
				this.getHibernateTemplate().load(c, id));
	}

	/**
	 * Delete POJO
	 * 
	 * @param basePOJO
	 */
	public void deletePOJO(BasePOJO basePOJO) {
		this.getHibernateTemplate().delete(basePOJO);
	}

	/**
	 * Load POJO By ID
	 * 
	 * @param c
	 * @param id
	 * @return BasePOJO
	 */
	public BasePOJO loadPOJO(Class c, Serializable id) {
		return (BasePOJO) this.getHibernateTemplate().load(c, id);
	}

	public BasePOJO getPOJO(Class c, Serializable id) {
		return (BasePOJO) this.getHibernateTemplate().get(c, id);
	}

	/**
	 * Load all POJO
	 * 
	 * @param c
	 * @return List
	 */
	public List loadAllPOJO(Class c) {
		return this.getHibernateTemplate().loadAll(c);
	}
}
